package cp1300assignment1;

/**
 *
 * @author Simon Marshall // jc209673 \\
 */
public class GridView {

    private char[][] grid;
    private GridModel project;

    /**
     *
     * @param project
     */
    public GridView(GridModel project) {
        this.project = project;
        int gs = project.getGridSize();
        grid = new char[gs][gs];
        setAll('?');
        buildHorizontalStreet(project.gethorizontalLaneNum());
        buildVerticalStreet(project.getverticalLaneNum());
    }

    /**
     *
     * @param character
     */
    public void setAll(char character) {
        for (int row = 0; row < grid.length; row++) {
            char[] tempRow = grid[row];
            for (int column = 0; column < tempRow.length; column++) {
                 grid[row][column] = character;
             }
        }
    }

    /**
     *
     * @param row
     * @param column
     * @param value
     */
    public void set(int row, int column, char value) {
        grid[row][column] = value;
    }

    void show() {
        for (int r = 0; r < grid.length; r++) {
            char[] tempRow = grid[r];
            for (int column = 0; column < tempRow.length; column++) {
                char character = grid[r][column];
                System.out.print(character);
            }
            System.out.println("");
        }
    }

    private void buildHorizontalStreet(int horizontalLaneNum) {
        int nr = grid.length;
        int middle = nr / 2;
        for (int r = 0; r < nr; r++) {
            char[] row = grid[r];
            if (r == middle) {
                setRow(row, ' ');
            }
        }
    }

    private void setRow(char[] row, char c) {
        for (int i = 0; i < row.length; i++) {
            row[i] = c;
        }
    }

    private void buildVerticalStreet(int verticalLaneNum) {
        int nc = project.getGridSize();
        int middle = nc / 2;
        for (int row = 0; row < grid.length; row++) {
            for (int column = 0; column < grid.length; column++) {
                if (column == middle) {
                    grid[row][column] = ' ';
                }
            }
        }
    }
}
